import { useDeprecateAppendToBody } from 'element-plus';
import { createRouter, createWebHistory } from 'vue-router';
import { menus } from './routerScript/routerMenus.js';
import { menusExpansionMap } from './routerScript/routerMaker';
import { metaWriter } from './routerScript/routerMeta';
import { autoRf } from './routerScript/routerQuery';

//生成路由
const { menuArr, menuMap } = menusExpansionMap(menus);
const routes = menuArr;

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
  menuMap
})

router.beforeEach((to, from, next) => {
  metaWriter(to);   //调用自动添加meta
  if (menuMap.get(to.name).mark == "menu") {
    next(autoRf(to, 10));
  } else {
    next(autoRf(to));
  }
})

export default router